﻿@using OPM.Class;
@using System.Web.Mvc;
@using OPM
@using OPM.MultiResource

@{
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    string caseId = ViewBag.caseid;
    GetOperatings[] Operating = ViewBag.operating;
    GetTimelineHeader[] timelineHeader = ViewBag.timeline_header;
    var timline = timelineHeader.First(o => o.case_id == caseId);
    ViewBag.timline = timelineHeader.First(o => o.case_id == caseId);
    CaseCustomerProfile[] customer_profile = ViewBag.cusPro;
    var oper = ViewBag.perating;
}

<div class="titleTab-line"></div>
<div class="timeLine-shortcut">
    <div class="timeLine-shortcut-box">
        <a href="@Url.Action("Index", "Timeline")"><span class="timeLine-shortcut-back floatL dBlock"></span></a>
        <div class="timeLine-shortcut-action">
            แสดงผลการปฎิบัติงาน : 
			       
            <select id="operating_status" name="operating_status">
                <option value="">ทั้งหมด</option>
                <option value="@U.org_id">เฉพาะหน่วยงานตนเอง</option>
            </select>
        </div>
        <div class="clear"></div>
    </div>
</div>


<div class="timeLineZone timeLineBoxFull">
    <div class="timeLineBox p-Relative timeLineBoxLeft">
        @foreach (var r in ViewBag.viewcase)
        {
            if (timline.timeline_type == "I")
            {
                 @Html.Raw("<span class=\"timeline-main-icon1\">")
            }
            else if (timline.timeline_type == "P")
            { 
                 @Html.Raw("<span class=\"timeline-main-icon2\">")
            }
            else if (timline.timeline_type == "N")
            {
                 @Html.Raw("<span class=\"timeline-main-icon3\">")
            }
            else
            {
                 @Html.Raw("<span class=\"timeline-main-icon4\">")
            }

            <div class="timeline-main-icon p-Absolute"></div>
            <svg class="timeline-main-triangle p-Absolute" xmlns="http://www.w3.org/2000/svg" version="1.1">
                <polygon points="0,0 0,13 13,13" />
            </svg>
            <div class="timeline-Title">
                <p>@r.type_text</p>
                <time>@r.created</time>
            </div>
            @Html.Raw("</span>")
            <div class="timeline-action p-Absolute" onclick="openActionBox();"></div>

@* @Html.Partial("_GroupListTimeline")*@
@*<div class="timeline-action-box dNone p-Absolute" style="background-position: -7px 35px; border-bottom: 1px solid #bbb; height: 154px; right: -9px; width: 113px;">*@
            
            <div class="timeline-action-box dNone p-Absolute">
                @Html.Partial("~/Views/GroupList/_CaseMenu.cshtml")
            </div> 
           
            <div class="detail-head">
                <p><strong>รหัสเรื่อง</strong> @r.case_code (@r.date_opened)</p>

                @if (customer_profile == null)
                {
                    <p>
                        <strong>ผู้เดือนร้อน</strong>  @Multi.assignCustomer
                        <a href="@Url.Action("LovSearchCustomer", "GroupList")?a=customer&id=@r.case_id" data-block="customer" class="callBoxCustomer"
                     onclick="callboxCustomer($(this).attr('href')); return false;"><span class="dBlock CustomerAddBtn"></span></a>
                    </p>
                }
                else
                {
                    var cus_pro = customer_profile.First(p => p.id == caseId);
                    <p><strong>ผู้เดือนร้อน</strong> @cus_pro.salutation_th @cus_pro.firstname_th  @cus_pro.lastname_th</p>
                }

            </div>
            <div class="timeline-Detail">
                <p><strong>@Multi.Objective_text : </strong>@r.objective_text</p>
                <p class="Detail-box2"><strong>ชั้นความลับ : </strong>@r.secret_text</p>
                <p class="Detail-box2"><strong>ชั้นความเร็ว : </strong>@r.severity_text</p>
                <p class="Detail-box2"><strong>ชั้นความสำคัญ : </strong>@r.priority_text</p>
                <p><strong>สาระสำคัญของเรื่อง : </strong>@r.summary_result_by_text</p>
                <p><strong>รายละเอียดของเรือง : </strong>@r.detail</p>

                @if (r.list_case_org_owner != null)
                {
                    foreach (var t in r.list_case_org_owner)
                    {

                    <p class="Detail-box1"><strong>หน่วยงานที่เกี่ยวข้อง : </strong>@t.org_text</p>
                    <p class="Detail-box2"><strong>สถานะการปฎิบัติการ : </strong>@t.case_org_status_text</p>
                    <p class="Detail-box2"><strong>ผลการปฎิบัติการ : </strong>@t.case_org_summary_result</p>
                    }
                }
                else
                {
                    
                    <p class="Detail-box1"><strong>หน่วยงานที่เกี่ยวข้อง : </strong></p>
                    <p class="Detail-box2"><strong>สถานะการปฎิบัติการ : </strong></p>
                    <p class="Detail-box2"><strong>ผลการปฎิบัติการ : </strong></p>
                }

                <p><strong>ผู้ถูกร้อง : </strong>@r.defendant</p>
                <p><strong>หน่วยงานที่เคยติดต่อ : </strong>@r.used_inform_with</p>
                <p><strong>สถานที่เกิดเหตุ : </strong>@r.case_area @r.district_text @r.subdistrict_text @r.province_text @r.postcode</p>
                <p><strong>เวลาที่เกิดเหตุ : </strong>@r.time_occurrenced</p>
                <p><strong>อยู่ระหว่างฟ้องร้อง / พิจารณาในชั้นศาล : @r.is_in_court_text </strong></p>
                <p><strong>สรุปผลการพิจารณา / ผลการวินิจฉัย : </strong>@r.case_org_summary_result</p>
                <p><strong>สภานะ : </strong>@r.status_text (@r.date_closed)</p>
            </div>
            
            <input type="hidden" name="case_id" id="case_id" value="@r.case_id" />
        
            <div class="p-Absolute timeline-Avatar-detail-box dNone">
                <div class="timeline-Avatar-detail"></div>
            </div>
        }


        @foreach (var a in Operating)
        {
            <div class="timeline-Comment2 Comment_tab_id" data-id="@a.id">
                <div class="floatL timeline-Comment-Avatar" data-userid="@a.officer_id">

                    @*<img src="~/images/icon-avatar.png" alt="" />*@
                    <img src="@a.image_base_64" alt="" />

                </div>
                <div class="timeline-Comment-Text">
                    <a href="@Url.Action("PopupGetOperating", "GroupList")?a=operating&id=@a.id" data-block="operating" onclick="callboxGetOperating($(this).attr('href')); return false;">
                        <p>@a.created_by_text</p>
                        <p class="CommentDetail">@a.org_text @a.officer_text @a.summary</p>
                    </a>
                    <input type="text" class="dNone CommentEditArea" value=""  data-id="@a.id">
                    <time class="timeago">@a.ShowDateTime</time>
                    <div class="EditComment" @*onclick="editComentBox('@a.id');"*@>|<a href="@Url.Action("EditOperating", "GroupList")?a=EditOperating&case_id=@a.id" data-block="operating" onclick="callcolorbox2($(this).attr('href')); return false;">แก้ไข</a></div>

                    <input type="hidden" id="type_id" value="@a.operating_type_id" />
                    <input type="hidden" id="status_id" value="@a.status_id" />
                    <input type="hidden" id="terminal_org_id" value="" />
                    <input type="hidden" id="terminal_owner_id" value="" />
                    <input type="hidden" id="date_opened" value="@a.date_opened" />
                    <input type="hidden" id="date_closed" value="@a.date_closed" />
                    <input type="hidden" id="summary" value="@a.summary" />
                    <input type="hidden" id="detail" value="" />
                    <input type="hidden" id="severity_id" value="@a.severity_id" />
                    <input type="hidden" id="priority_id" value="@a.priority_id" />
                    <input type="hidden" id="secret_id" value="@a.secret_id" />
                </div>
                <div class="clear2"></div>
            </div>
        }


    </div>
</div>

<div class="dNone">
    <div id="inline_content">
        <div class="SaveSuccess">
            <div class="SaveSuccessTab1">บันทึกข้อมูลแล้ว</div>
            @*<div class="SaveSuccessTab2">รหัสการให้บริการ : <span>xyz12345678</span></div>*@
            <div class="SaveSuccessTab3" onclick="$.colorbox.close();">@Multi.finish</div>
        </div>
    </div>
</div>

<script src="~/js/timeline-detail.js"></script>
<script src="~/js/Operating.js"></script>
<script src="~/js/opm_uploadfile.js"></script>

<script>

    function callboxGetOperating(link) {
        $.colorbox({
            iframe: true,
            width: "550px",
            height: "500px;",
            fastIframe: false,
            href: link
        });
    }

    function callboxEditOperating(link) {
        $.colorbox({
            iframe: true,
            width: "550px",
            height: "500px;",
            fastIframe: false,
            href: link
        });
    }


    var addCustomerStaus = false;
    var addCustomerUrl = "";
    function callboxCustomer(link) {

        $.colorbox({
            iframe: true,
            width: "550px",
            height: "400px",
            href: link,
            fastIframe: false,
            onClosed: function () {
                if (addCustomerStaus) {
                    $.colorbox({
                        iframe: true,
                        width: "720px",
                        height: "90%",
                        fastIframe: false,
                        href: addCustomerUrl
                    });
                }
                addCustomerStaus = false;
            }
        });

    }
    function addCustomerAction(link) {
        addCustomerStaus = true;
        addCustomerUrl = link;

        $.colorbox.close();
    }
    function savedataform() {
        $.colorbox({
            inline: true,
            width: "50%",
            href: "#inline_content",
            fastIframe: false,
            onClosed: function () {
            }
        });
    }

    $(document).ready(function () {

        $("#operating_status").change(function () {

            var id = $("#case_id").val();
            var status = $("#operating_status option:selected").val();

            window.location.href = "/GroupList/ViewCase?id="+id+"&status="+status;


           
        });

        $(".CommentEditArea").keyup(function (event) { // เมื่อพิมพ์คำค้นหาในกล่องค้นหา  

            if (event.keyCode == 13) {
                var operating_id = $(this).attr('data-id');
                var str = $(this).val();
                var type_id = $("#type_id").val();
                var status_id = $("#status_id").val();
                var terminal_org_id = $("#terminal_org_id").val();
                var terminal_owner_id = $("#terminal_owner_id").val();
                var date_opened = $("#date_opened").val();
                var date_closed = $("#date_closed").val();
                var summary = $("#summary").val();
                var detail = $("#detail").val();
                var severity_id = $("#severity_id").val();
                var priority_id = $("#priority_id").val();
                var secret_id = $("#secret_id").val();



                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    cache: false,
                    url: '/GroupList/EditOperating',
                    data: {
                        operating_id: operating_id, comment: str, type_id: type_id, status_id: status_id,
                        terminal_org_id: terminal_org_id, terminal_owner_id: terminal_owner_id, date_opened: date_opened,
                        date_closed: date_closed, summary: summary, detail: detail, severity_id: severity_id, priority_id: priority_id,
                        secret_id: secret_id
                    }
                    ,
                    success: function (response, textStatus, jqXHR) {
                        savedataform();
                        location.reload();
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert('Error - ' + errorThrown);
                    }
                });


                //success
                var box = $('div[data-id="' + id + '"]');
                box.find('.CommentEditArea').val('').hide();
                box.find('.CommentDetail').text(str).show();
            }
        });

    });

    function editComentBox(id) {
        var box = $('div[data-id="' + id + '"]');
        var str = box.find('.CommentDetail').text();
        box.find('.CommentDetail').hide();
        box.find('.CommentEditArea').val(str).css('display', 'block');
    }

</script>

